package com.example.ui_view;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class RecylerViewActivity extends AppCompatActivity {
    RecyclerView rv_contact;
    int[] pic = new int[]{R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05,R.mipmap.img06
            ,R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05,R.mipmap.img06,R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05,R.mipmap.img06
            ,R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05,R.mipmap.img06};
    String[] str = new String[]{"1111","2222","3333","4444","5555","6666","1111","2222","3333","4444","5555","6666","1111","2222","3333","4444","5555","6666","1111","2222","3333","4444","5555","6666"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyler_view);
        rv_contact = findViewById(R.id.rv_contact);
        rv_contact.setLayoutManager(new LinearLayoutManager(RecylerViewActivity.this));
        contactadaper adaper = new contactadaper();
        rv_contact.setAdapter(adaper);
    }
    class contactHoder extends RecyclerView.ViewHolder{
        TextView tv_contact;
        ImageView img_contact;
        public contactHoder(@NonNull View itemView) {
            super(itemView);
            tv_contact = itemView.findViewById(R.id.tv_contact);
            img_contact = itemView.findViewById(R.id.img_contact);
        }
    }

    class contactadaper extends RecyclerView.Adapter<contactHoder>{

        @NonNull
        @Override
        public contactHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            contactHoder hoder = new contactHoder(LayoutInflater.from(RecylerViewActivity.this).inflate(R.layout.recyview_item,parent,false));
            return hoder;
        }

        @Override
        public void onBindViewHolder(@NonNull contactHoder holder, int position) {
            holder.img_contact.setImageResource(pic[position]);
            holder.tv_contact.setText(str[position]);

        }

        @Override
        public int getItemCount() {
            return pic.length;
        }
    }
}
